import { ComponentPlugin } from "src/shims";
import { Plugin, App } from "vue";

const installPlugins: ComponentPlugin[] = [];

export function installPlugin<T extends { name: string }>(
  Component: T,
  plugins?: ComponentPlugin[]
) {
  return {
    ...Component,
    install(app: App) {
      app.component(Component.name, Component);

      plugins &&
        plugins.forEach((plugin: ComponentPlugin) => {

          if (installPlugins.indexOf(plugin) === -1) {
            app.use(plugin);
            installPlugins.push(plugin);
          }
        });
    }
  };
}
